#define _CRT_SECURE_NO_WARNINGS 1

#include<stdbool.h>

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
bool judge(int tmp)
{
    int num = tmp;
    int flag = 0;
    while (tmp > 0)
    {
        flag = tmp % 10;
        tmp /= 10;
        if (flag == 0)
        {
            return false;
        }
        if (num % flag != 0)
        {
            return false;
        }
    }
    return true;
}
int* selfDividingNumbers(int left, int right, int* returnSize) {
    int i = 0;
    int count = 0;
    int* ret = malloc(sizeof(int) * (right - left + 1));
    for (i = left; i <= right; i++)
    {
        if (judge(i))
        {
            ret[count++] = i;
        }
    }
    *returnSize = count;
    return ret;
}

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* productExceptSelf(int* nums, int numsSize, int* returnSize) {
    int* answer = malloc(sizeof(int) * numsSize);
    int i = 0;
    int left = 1;
    int right = 1;

    for (i = 0; i < numsSize; i++)
    {
        answer[i] = left;

        left *= nums[i];
    }
    for (i = numsSize - 1; i >= 0; i--)
    {
        answer[i] *= right;

        right *= nums[i];
    }
    *returnSize = numsSize;
    return answer;
}